<!doctype html>
<html lang="en" class="fixed">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>自动分配2</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        ul, li, ol, li {
            list-style: none;
        }

        a {
            color: #000;
            text-decoration: none;
        }

        body {
            background: #F4F4F4;
        }

        .content {
            width: 1200px;
            margin: 0 auto;
            padding: 20px 30px;
            background: #fff;
        }

        .content .title .title-role p {

        }

        .content .title .title-role .title-btn {
            float: right;
            margin-top: -30px;
        }

        .content .title .title-role .title-btn button {
            padding: 6px 10px;
            margin: 0 4px;
            border-radius: 5px;
        }

        .content .title .title-role .title-btn button:nth-of-type(1) {
            background: #108EE9;
            color: #fff;
            border: none;
            font-size: 12px;
        }

        .content .title .title-role .title-btn button:nth-of-type(2) {
            background: #108EE9;
            color: #fff;
            border: none;
            font-size: 12px;
        }

        .content .title .title-role .title-btn button:nth-of-type(3) {
            background: #D75234;
            color: #fff;
            border: none;
            font-size: 12px;
        }

        .content .title h2 {
            width: 100%;
            padding: 10px 20px;
            font-size: 12px;
            background: #f4f4f4;
            border-radius: 5px;
            margin-top: 24px;
        }

        .content .title p.name {
            font-size: 12px;
            margin-top: 20px;
        }

        .content .title p.name input {
            width: 180px;
            height: 24px;
            border: 1px #ccc solid;
            border-radius: 5px;
            text-indent: 10px;
        }

        .content .title p.name span {
            margin-left: 40px;
        }

        .content .module h3 {
            font-size: 12px;
            width: 100%;
            background: #f4f4f4;
            padding: 10px 20px;
            border-radius: 5px;
        }

        .content .module .module-content {
            margin-top: 30px;
            padding-right: 30px;
        }

        .content .module .module-content ul {
            display: inline-block;
            border: 1px #eee solid;
        }

        .content .module .module-content ul li {
            border-bottom: 1px #eee solid;
            line-height: 30px;
            padding: 0 30px;
            font-size: 12px;
            color: #333;
            cursor: pointer;
        }

        .content .module .module-content ul li:last-child {
            border-bottom: none;
        }

        .content .module .module-content ul li:hover {
            background: #E7F4FD;
            color: #3F93EC;
        }

        .content .module .module-content ul li.active {
            background: #E7F4FD;
            color: #3F93EC;
        }

        .content .module .module-content .module-tabs {
            float: right;
            width: 80%;
        }

        .content .module .module-content .module-tabs > div {
            width: 100%;
        }

        .content .module .module-content .module-tabs .one:nth-of-type(1) {
            display: inline-block;
        }

        .content .module .module-content table {
            width: 100%;
        }

        .content .module .module-content table thead {
            background: #f4f4f4;
        }

        .content .module .module-content table thead tr th {
            padding: 10px 20px;
            border: 1px #eee solid;
            font-size: 12px;
        }

        .content .module .module-content table tbody tr td {
            border: 1px #eee solid;
            padding: 10px;
            font-size: 12px;
        }

        .content .module .module-content table tbody tr td span {
            margin: 0 4px;
        }

        .content .module .module-content table tbody tr td:last-child {
            color: #008DE7;
        }
    </style>
</head>

<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>
<div class="wrap">
    <div class="class-box">
        <div class="class-box-head">
            <div class="class-box-title">
                <h3>自动分配</h3>
                <div class="class-box-tools">

                </div>
            </div>
            <form id="app_submit">
                <div class="from-top row">
                    <div class="from-top-left col-md-8">
                        <ul>
                            <li>
                                <label>是否开启自动分配:</label>
                                <select class="form-control" name="cfg_value" id="cfg_value" class="cfg">
                                    <?php foreach ($aWhether as $aTmp) { ?>
                                        <option value="<?php xcho($aTmp['dict_value']) ?>"
                                            <?php if ($aTmp['dict_value'] == $bWether) { ?>
                                                selected="selected"
                                            <?php } ?>><?php xcho($aTmp['cn_name']) ?></option>
                                    <?php } ?>
                                </select>
                            </li>
                        </ul>
                    </div>
                    <div class="from-top-right col-md-4">
                        <div class="form-inline">
                            <label >查看范围:</label>
                            <input results="s" class="group-picker form-control" id="scale_name" name="scale_name" type="search"
                                   value="<?php xcho($aSearch['scale_name']) ?>"
                                   url="<?php xcho($sSearchRange) ?>"
                                   search_url="<?php xcho($sSearch) ?>">
                            <input type="hidden" id="scale_id" name="scale_id" value="<?php xcho($aSearch['scale_id']) ?>">
                            <input type="hidden" id="scale_type" name="scale_type" value="<?php xcho($aSearch['scale_type']) ?>">
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="class-box-body">
            <table class="table table-bordered table-hover table table-bordered table-striped auto-allot">
                <thead>
                <th></th>
                <th>等级</th>
                <?php foreach ($aDates as $aDate) { ?>
                    <th><?php xcho(date('m.d', $aDate) . "\n 上午") ?></th>
                    <th><?php xcho(date('m.d', $aDate) . "\n 下午") ?></th>
                <?php } ?>
                </thead>
                <tbody>
                <?php foreach ($aGroups as $aGroup) { ?>
                    <tr>
                        <td colspan="16"><h3><?php xcho($aGroup['cn_name']) ?></h3></td>
                    </tr>
                    <?php foreach ($aUsers as $aUser) { ?>
                        <?php if ($aUser['group_id'] == $aGroup['id']) { ?>
                            <tr>
                                <td><?php xcho($aUser['full_name']) ?></td>
                                <td>
                                    <select class="rank form-control" name="rank_value" id="<?php xcho($aUser['id']) ?>">
                                        <option value="0">不分配</option>
                                        <?php foreach ($aRankList as $aTmp) { ?>
                                            <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                        <?php } ?>
                                    </select>
                                </td>
                                <?php foreach ($aUser['pks'] as $pk) { ?>
                                    <td><input lay-skin="primary" class="check" id="<?php xcho($pk) ?>"
                                               name="check_value" type="checkbox"></td>
                                <?php } ?>
                            </tr>
                        <?php } ?>
                    <?php } ?>
                <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="modal fade" id="info-modal-group" tabindex="-1" role="dialog" aria-labelledby="modal-info-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header state modal-info">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modal-info-label"><i class="fa fa-info"></i></h4>
            </div>
            <div class="modal-body" style="min-height: 150px;">
                <ul class="ztree" id="group"></ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="sureGroup" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" id="returnGroup" data-dismiss="modal">返回</button>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="saveUrl" name="saveUrl" value="<?php xcho($saveUrl) ?>"/>
<input type="hidden" id="ajaxUrl" name="ajaxUrl" value="<?php xcho($ajaxUrl) ?>"/>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script type="text/javascript" src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.cookie.js')) ?>"></script>
<script type="text/javascript" src="<?php xcho(loadSource('/assets/js/topjui.config.js')) ?>"></script>
<script type="text/javascript">topJUI.config.mainPage = true;</script>
<!-- TopJUI框架核心 -->
<script type="text/javascript" src="<?php xcho(loadSource('/assets/js/topjui.core.min.js')) ?>"></script>
<!-- TopJUI中文支持 -->
<script type="text/javascript" src="<?php xcho(loadSource('/assets/js/locale/topjui.lang.zh_CN.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layer-v3.0.3/layer/layer.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.core.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.excheck.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.exedit.js')) ?>"></script>
<script>
    $(function () {
        //保存编辑内容
        $("#cfg_value").on("change", function () {
            var data = {
                'cfg_key':'allot',
                'saveType':'config',
                'cfg_value':$("#cfg_value").val(),
            };
            $.ajax({
                url: $("#saveUrl").val(),
                data: data,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.success == 1) {
                        layer.msg('保存成功!');
                    } else {
                        layer.msg('保存失败！');
                    }
                },
                complete: function () {

                },
                error: function () {

                }
            });
        });
        $(".rank").on("change", function () {
            var data = {
                'user_id':parseInt($(this).attr('id')),
                'rank_value':$(this).val(),
                'saveType':'user',
            };
            var oObject = $(this);
            $.ajax({
                url: $("#saveUrl").val(),
                data: data,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.success == 1) {
                        layer.msg('保存成功!');
                        location.reload();
                    } else {
                        layer.msg('保存失败！');
                    }
                },
                complete: function () {

                },
                error: function () {

                }
            });
        });
        $(".check").on("click", function () {
            if($(this).is(':checked')){
                var bIsCheck = 'yes';
            }else {
                var bIsCheck = 'no';
            }
            var data = {
                'pk':$(this).attr('id'),
                'is_check':bIsCheck,
                'saveType':'time',
            };
            $.ajax({
                url: $("#saveUrl").val(),
                data: data,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.success == 1) {
                        layer.msg('保存成功!');
                    } else {
                        layer.msg('保存失败！');
                    }
                },
                complete: function () {

                },
                error: function () {

                }
            });
        });
        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]);
            return null; //返回参数值
        }

        $(".group-picker").focus(function () {
            $('#info-modal-group').modal({
                keyboard: false,
                backdrop: false
            });
            $('#info-modal-group').on('shown.bs.modal', function (e) {
                // 关键代码，如没将modal设置为 block，则$modala_dialog.height() 为零
                $(this).css('display', 'block');
                $(this).find('.modal-dialog').css({
                    'margin-top': "100px"
                });
            });
        });
        $("#sureGroup").on("click", function () {
            var zTree = $.fn.zTree.getZTreeObj("group"),
                nodes = zTree.getSelectedNodes(),
                treeNode = nodes[0];
            if (nodes.length == 0) {
                alert("请先选择一个节点");
                return;
            }
            $(".group-picker").val(treeNode.name);
            $("#scale_id").val(treeNode.id);
            $("#scale_type").val(treeNode.scale_type);
            /**
             * 调用后台
             */
            $("#app_submit").submit();
        })
        var settingGroup = {
            view: {
                selectedMulti: false
            },
            edit: {
                enable: false
            },
            data: {
                keep: {
                    parent: true,
                    leaf: true
                },
                simpleData: {
                    enable: true
                }
            }
        };
        var zNodes = getListData();

        function getListData() {
            var data_list;
            $.ajax({
                url: $(".group-picker").attr('url'),
                type: 'post',
                async: false,
                dataType: 'json',
                success: function (data) {
                    if (data.success == 1) {
                        data_list = data.data_list.aGroup;
                    } else {
                    }
                },
                complete: function () {
                },
                error: function () {

                }
            });
            return data_list;
        }

        $.each(zNodes, function (i, item) {
            item.isParent = true;
        })

        $(document).ready(function () {
            $.fn.zTree.init($("#group"), settingGroup, zNodes);
            getAjaxData();
        });
        function getAjaxData() {
            var ajaxUrl = $("#ajaxUrl").val();
            var aUserIDs = new Array();
            var aCheckIDs = new Array();
            $("select[name='rank_value']").each(function () {
                aUserIDs.push($(this).attr('id'));
            })
            /*$("input[type='checkbox']").each(function () {
                aCheckIDs.push($(this).attr('id'))
            })*/
            $.ajax({
                url: ajaxUrl,
                type: 'post',
                data: {
                    user_ids: aUserIDs,
//                    check_ids: aCheckIDs,
                },
                dataType: 'json',
                success: function (data) {
                    if (data.success == 1) {
                        $.each(data.data.aAppUser, function () {
                            $("#" + $(this)[0]['user_id']).val($(this)[0]['rank_value']);
                        })
                        $.each(data.data.aAppTime, function () {
                            $("#" + $(this)[0]['pk']).removeAttr('disabled');
                            if ($(this)[0]['is_check'] == 'yes') {
                                $("#" + $(this)[0]['pk']).attr('checked', true);
                            }
                        })
                    } else {
                    }
                },
                complete: function () {
                },
                error: function () {

                }
            });
        }

        /*$("#sureGroup").on("click", function () {
         var zTree = $.fn.zTree.getZTreeObj("group"),
         nodes = zTree.getSelectedNodes(),
         treeNode = nodes[0];
         if (nodes.length == 0) {
         alert("请先选择一个节点");
         return;
         }
         $(".group-picker").val(treeNode.name);
         $("#scale_id").val(treeNode.id);
         $("#scale_type").val(treeNode.scale_type);
         })*/
    });

</script>
<?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>

<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
